package cn.qzzg.util;

import cn.qzzg.common.ResultBean;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Serializable;

/**
 * Response响应工具类
 */
public class ResponseUtil implements Serializable {
    public static void writer(HttpServletRequest request, HttpServletResponse response, ResultBean<?> result) {
        response.setContentType("application/json;charset=utf-8");
        response.setHeader("Access-Control-Allow-Origin", "*");
        try {
            ServletOutputStream out = response.getOutputStream();
            out.write(JSON.toJSONString(result).getBytes());
            out.flush();
            out.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}